package com.bgs.travelapp.MyCollection.service.Impl;

import com.bgs.travelapp.MyCollection.entity.MyCollectionEntity;
import com.bgs.travelapp.MyCollection.mapper.MyCollectionMapper;
import com.bgs.travelapp.MyCollection.service.MyCollectionService;
import com.bgs.travelapp.result.CommonResult;
import com.bgs.travelapp.scenic.service.ScenicService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * 我的收藏 （前端---我的收藏）
 * gpd 2022-08-09 15点53分
 */
@Service
public class MyCollectionServiceImpl implements MyCollectionService {

    @Resource
    MyCollectionMapper myCollectionMapper;

    @Resource
    ScenicService scenicService;

    /**
     * 添加收藏的景区
     * gpd 2022-08-09 16点02分 （前端展示---景区收藏）
     * @param myCollectionEntity
     * @return
     */
    @Override
    public Integer collectionScenic(MyCollectionEntity myCollectionEntity) {
        myCollectionEntity.setCollectionTypeId(1);
        myCollectionEntity.setCollectionTypeName("景区");
        int i =0;
        //新增景区收藏数+1
        i = scenicService.increaseScenicCollection(myCollectionEntity.getScenicId());
        if(i>0){
            return myCollectionMapper.insertSelective(myCollectionEntity);
        }else{
            return 0;
        }
    }

    /**
     * 查询用户是否收藏景区id
     * gpd 2022-08-09 16点58分 （前端展示---景区收藏）
     * @param id
     * @param userId
     * @return
     */
    @Override
    public List<MyCollectionEntity> getCollectionScenic(Integer id,Integer userId) {
        MyCollectionEntity myCollectionEntity  = new MyCollectionEntity();
        myCollectionEntity.setScenicId(id);
        myCollectionEntity.setUserId(userId);
        return myCollectionMapper.select(myCollectionEntity);
    }

    /**
     * 取消收藏景区
     * gpd 2022-08-09 17点08分 （前端展示---景区收藏）
     * @param id
     * @param scenicId
     * @return
     */
    @Override
    public Integer deleteCollectionScenic(Integer id,Integer scenicId) {
        MyCollectionEntity myCollectionEntity = new MyCollectionEntity();
        myCollectionEntity.setId(id);
        int i =0;
        i = scenicService.deleteScenicCollection(scenicId);
        if(i>0){
            return myCollectionMapper.deleteByPrimaryKey(myCollectionEntity);
        }
        else{
            return 0;
        }

    }

    /**
     * 查询用户已选择的标签页类型的收藏 （前端展示----我的收藏）
     * gpd 2022-08-10 11点16分
     * @param collectionName
     * @param userId
     * @return
     */
    @Override
    public List<MyCollectionEntity> getMyCollection(String collectionName,Integer userId) {
        MyCollectionEntity myCollectionEntity = new MyCollectionEntity();
        myCollectionEntity.setCollectionTypeName(collectionName);
        myCollectionEntity.setUserId(userId);
        return myCollectionMapper.select(myCollectionEntity);
    }




}
